let App = getApp();

Page({
  data: {
    // banner轮播组件属性
    indicatorDots: true, // 是否显示面板指示点
    autoplay: true, // 是否自动切换
    interval: 3000, // 自动切换时间间隔
    duration: 800, // 滑动动画时长
    imgHeights: {}, // 图片的高度
    imgCurrent: {}, // 当前banne所在滑块指针

    features: [{
      name: '最新动态',
      url: 'postList/postList',
      ico: '../../images/icon/icon_post.png'
    },{
      name: '合作院校',
      url: 'partner/partner',
      ico: '../../images/icon/icon_coop.png'
    },{
      name: '联系我们',
      url: 'about/about',
      ico: '../../images/icon/icon_contact2.png'
    }],


    // 页面元素
    items: {},
    newestPost: [],

    scrollTop: 0,
  },

  onLoad: function() {
    // 设置页面标题
    App.setTitle();
    // 设置navbar标题、颜色
    App.setNavigationBar();

    // 获取首页数据
    this.getIndexData();
  },

  onContact: function() {

  },

  /**
   * 获取首页数据
   */
  getIndexData: function() {
    let _this = this;
    App._get('index/page', {}, function(result) {
      _this.setData(result.data);
    });
  },

  bindChange: function(e) {
    let itemKey = e.target.dataset.itemKey,
      imgCurrent = this.data.imgCurrent;
    // imgCurrent[itemKey] = e.detail.current;
    imgCurrent[itemKey] = e.detail.currentItemId;
    this.setData({
      imgCurrent
    });
  },

  goTop: function(t) {
    this.setData({
      scrollTop: 0
    });
  },

  onNavigator: function(e){
    let url = e.currentTarget.dataset.url;
    wx.switchTab({
      url: '../' + url,
      fail: function() {
        wx.navigateTo({
          url: '../' + url,
          fail: function() {

          }
        })
      }
    })
  },

  scroll: function(t) {
    this.setData({
      indexSearch: t.detail.scrollTop
    }), t.detail.scrollTop > 300 ? this.setData({
      floorstatus: !0
    }) : this.setData({
      floorstatus: !1
    });
  },

  onShareAppMessage: function() {
    return {
      title: "小程序首页",
      desc: "",
      path: "/pages/index/index"
    };
  }
});
